package com.huluobo.a2302mdmdemo.demo

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.staggeredgrid.LazyVerticalStaggeredGrid
import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridCells
import androidx.compose.foundation.lazy.staggeredgrid.items
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.Divider
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage

/**
 *  Created by LC on 2025/7/18.
 */

data class Student(val name: String, val desc: String, val img: String)

@Composable
fun MyList() {
    val list = mutableListOf<Student>()

    for (i in 1..20) {
        list.add(
            Student(
                "张三$i",
                "这是我的个人简介:$i",
                "https://img1.baidu.com/it/u=4214113141,2036563917&fm=253&app=120&size=w931&n=0&f=JPEG&fmt=auto?sec=1729098000&t=0662d2b383091882ccdd43ad060de2a7"
            )
        )
    }
    Column {
//        LazyRow(
//            content = {
//                items(list) {
//                    StudentItem(student = it)
//                }
//            }, horizontalArrangement = Arrangement.spacedBy(10.dp), modifier = Modifier
//                .fillMaxWidth()
//                .padding(10.dp)
//        )
//        LazyRow(
//            content = {
//                items(list) {
//                    StudentItem(student = it)
//                }
//            }, horizontalArrangement = Arrangement.spacedBy(10.dp), modifier = Modifier
//                .fillMaxWidth()
//                .padding(10.dp)
//        )
//        LazyColumn(
//            content = {
//                items(list) {
//                    StudentItem(student = it)
//                }
//            },
//            verticalArrangement = Arrangement.spacedBy(10.dp),
//            modifier = Modifier
//                .fillMaxWidth()
//                .padding(10.dp)
//        )
//        LazyHorizontalGrid(rows = GridCells.Fixed(2), content = {
//            items(list) {
//                StudentItem(student = it)
//            }
//        })
//        LazyVerticalGrid(columns = GridCells.Fixed(2), content = {
//            items(list) {
//                StudentItem(student = it)
//            }
//        })

        LazyVerticalStaggeredGrid(columns = StaggeredGridCells.Fixed(2), content = {
            items(list) {
                StudentItem(student = it)
            }
        })
    }
}

@Composable
fun StudentItem(student: Student) {
    Column(Modifier.padding(10.dp), verticalArrangement = Arrangement.spacedBy(10.dp)) {
        Row {
            AsyncImage(
                model = student.img, contentDescription = "", modifier = Modifier
                    .size(80.dp)
                    .clip(CircleShape), contentScale = ContentScale.Crop
            )
            Spacer(modifier = Modifier.width(10.dp))
            Column(Modifier.height(80.dp), verticalArrangement = Arrangement.SpaceAround) {
                Text(text = student.name)
                Text(text = student.desc, color = Color.LightGray)
            }
        }
        Spacer(modifier = Modifier.height(10.dp))
        Divider(thickness = 0.5.dp)
    }
}